<%--
  Created by IntelliJ IDEA.
  User: bnahlz
  Date: 2020/1/12
  Time: 17:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>mysqlExecute 登录</title>
    <meta charset="utf-8">
    <meta name="author" content="Kodinger">
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/my-login.css">

    <!-- FAVICON -->
   <%-- <link href="img/favicon.png" rel="shortcut icon" />--%>
    <link rel="icon" href="img/favicon.png" type="image/x-icon">

</head>
<%
    if(session.getAttribute("LOGIN_DATA")!=null){   //检测是否登录
        response.sendRedirect("db/index");
    }
%>
<body class="my-login-page">
<section class="h-100">
    <div class="container h-100">
        <div class="row justify-content-md-center h-100">
            <div class="card-wrapper">
                <div class="brand">
                    <img src="img/timg.jpg">
                </div>
                <center><h4 class="card-title" >mysqlExecute数据库管理</h4></center>
                <div class="card fat">
                    <div class="card-body">
                        <a id="msg" style="color:red" ></a>
                        <h4 class="card-title">登录</h4>

                        <form method="POST">

                            <div class="form-group">
                                <label for="name">用户名
                                    <a href="register.jsp" class="float-right">
                                        还没有账号?
                                    </a>
                                </label>
                                <input placeholder="请输入用户名"  id="name" type="text" class="form-control" name="name" value="" >
                            </div>

                            <div class="form-group">
                                <label for="password">密码
                                    <a href="updatePasswordEmailVeri.jsp" class="float-right">
                                        忘记密码?
                                    </a>
                                </label>
                                <input placeholder="请输入密码"  id="password" type="password" class="form-control" name="password">
                            </div>

                            <div class="form-group">
                                <label>
                                    <%-- <input  type="checkbox" name="remember"> Remember Me--%>
                                </label>
                            </div>

                            <div class="form-group no-margin">
                                <button id="submit" type="button" class="btn btn-primary btn-block">
                                    登录
                                </button>
                            </div>
                            <br>
                            <center><img  id="submitDisImg"></center>
                        </form>
                    </div>
                </div>
                <div class="footer">
                    测试账号：test  密码：123<br><br>
                    Copyright&copy;NextStep Company 2020 我们砥砺前行，不畏风雨。<br><br>
                    <a href="https://blog.csdn.net/weixin_40652498" title="下一步科技" target="_blank">下一步科技</a>

                </div>
            </div>
        </div>
    </div>
</section>



</body>

<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
<script type="text/javascript">
        document.getElementById("submit").onclick=function(){
        document.getElementById("msg").innerHTML="";

        var name = document.getElementById("name").value;
        var password = document.getElementById("password").value;
        if(name==""){
            alert("请输入用户名。");
            return ;
        }
        if(password==""){
            alert("请输入密码。");
            return ;
        }

        document.getElementById("submitDisImg").src="img/wait.gif";
        $.ajax({
            url:"user/equale",     //请求地址
            contentType:"application/json;charset=UTF-8",  //传输数据类型
            data:JSON.stringify({name:name,password: password}),  //要传输的数据
            dataType:"json",   //返回值类型
            type:"post",     //请求方式
            success:function(msg){  //data表示服务端响应的数据
                if (msg=="success") {//根据返回值进行跳转
                    window.location.href = 'db/index';
                }else{
                    document.getElementById("submitDisImg").src="";
                    document.getElementById("msg").innerHTML="用户名或密码错";
                }
            },
            complete : function(xhr, status) {
                //拦截器实现超时跳转到登录页面
                // 通过xhr取得响应头
                var REDIRECT = xhr.getResponseHeader("REDIRECT");
                //如果响应头中包含 REDIRECT 则说明是拦截器返回的
                if (REDIRECT == "REDIRECT"){

                    //重新跳转到 login.html
                    window.location.href = xhr.getResponseHeader("CONTENTPATH");
                }
            }

        });
    }

</script>
</html>
